package com.xjtu.chapter05.ex5_4;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/8/16 21:22
 */
public class HitGreenPig {
    public static void main(String[] args) {
        BlueBird one = new BlueBird();
        one.chirp();  //通过对象调用方法，属于静态绑定
        one.shoot();

        WhiteBird two = new WhiteBird();
        two.chirp();
        two.shoot();

        RedBird three = new RedBird();
        three.chirp();
        three.shoot();

        AngryBird[] angryBirds = new AngryBird[3];//生成父类对象数组
        int n;
        for (int i = 0; i < angryBirds.length; i++) {
            n = (int) (Math.random() * 3);//随机产生0-2中的一个数
            switch (n) {
                case 0:
                    angryBirds[i] = new BlueBird();
                    break;
                case 1:
                    angryBirds[i] = new WhiteBird();
                    break;
                case 2:
                    angryBirds[i] = new RedBird();
            }

        }
        for (int j = 0; j < angryBirds.length; j++) {
            angryBirds[j].chirp();
            angryBirds[j].shoot();
        }
    }
}
